# -*-coding:utf-8 -*-
# str="a,b,c,1,2,3,-,+,="
# print(list(str))
# for i,value in enumerate(list(str)):
#     print('value==', value)
#     print('type(value)==', type(value))

# str="a,b,c,d,e"
# str1=str.replace(",","")
# print(str1)
# print(str[::-1])
# ss=""
# for i in range(len(str1)):
#     ss+=str1[-(i+1)]
# print(ss)
# print(type(list(str1).reverse()))
# print(list(str1).reverse())

from PIL import Image

# k=20
# for i in range(20,0,-1):
#     print i

import copy

# a = [1, 2, 3, 4, ['a', 'b']] #原始对象
# b = a  # 赋值，传对象的引用
# c = copy.copy(a)  # 对象拷贝，浅拷贝
# d = copy.deepcopy(a)  # 对象拷贝，深拷贝
#
# a.append(5)  # 修改对象a
# a[4].append('c')  # 修改对象a中的['a', 'b']数组对象
# a.remove(2)
#
# print 'a = ', a
# print 'b = ', b
# print 'c = ', c
# print 'd = ', d

from collections import deque
def search(lines, pattern, history=5):
    previous_lines = deque(maxlen=history)
    for line in lines:
        if pattern in line:
            print "begin"
            yield line, previous_lines
            print "end"
        print "hehe"
        previous_lines.append(line)
# Example use on a file

# import heapq
#
# portfolio = [{'name': 'IBM', 'shares': 100, 'price': 91.1},{'name': 'AAPL', 'shares': 50, 'price': 543.22},{'name': 'FB', 'shares': 200, 'price': 21.09},{'name': 'HPQ', 'shares': 35, 'price': 31.75},{'name': 'YHOO', 'shares': 45, 'price': 16.35},{'name': 'ACME', 'shares': 75, 'price': 115.65}]
# cheap = heapq.nsmallest(3, portfolio, key=lambda s: s['price'])
# expensive = heapq.nlargest(3, portfolio, key=lambda s: s['price'])
# print cheap
# print expensive


# def some_generator():
#     print "start"
#     data="abc"
#     result=yield  data
#     print result+"==============="
# f=some_generator()
# result=None
# while True:
#     try:
#         print "---------------"
#         data = f.send(result)
#         print(data)
#         result = '?????????????????'
#         print result+"lalala"
#     except StopIteration:
#         break
#
# import subprocess
# print subprocess.check_output('adb shell ls ',shell=True)

import os,sys
def findfile(start, name):
    for relpath, dirs, files in os.walk(start):
        print("realpath==="+relpath)
        print("dirs===" + "---".join(dirs))
        print("files===" + "---".join(files))
        if name in files:
            full_path = os.path.join(start, relpath, name)
            print(full_path)
            print(os.path.normpath(os.path.abspath(full_path)))
            return


if __name__ == '__main__':
    findfile("D:/Android/android-sdk", "SDK Readme.txt")
    pass
    # with open(r'001weather.yaml') as f:
    #     for line, prevlines in search(f, 'pixel', 5):
    #         print "ggggggg============="
    #         for pline in prevlines:
    #             print(pline)
    #         print(line)
    #         print('-' * 20)

